package ioStream;

import java.io.File;
import java.io.FilenameFilter;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2024/09/19
 * 文件类练习
 */
public class FileTest {
    public static void main(String[] args) {
        listAll(new File("C:\\Users\\白草风归\\Music\\ceshi\\img"));
    }

    public static void listAll(File parent) {
        MyFilter myFilter = new MyFilter();
        File[] children  = parent.listFiles(myFilter);

        for (int i = 0; i < children.length; i++) {
            // 如果子文件是个文件夹，则递归调用
            if(!children[i].isFile()){
                listAll(children[i]);
            }else {
                System.out.println(children[i].getName());
            }
        }
    }

    //

    /**
     * 定义文件过滤器
     */
    static class MyFilter implements FilenameFilter {
        @Override
        public boolean accept(File dir, String name) {
            return name.contains(".png") || dir.isDirectory();
        }
    }
}